package io.xxx.omni.oss.custom

import com.google.gson.JsonArray
import com.google.gson.JsonObject
import io.xxx.omni.oss.common.gson
import io.xxx.omni.oss.common.toLocalDateTime
import io.xxx.omni.oss.domain.Document
import io.xxx.omni.oss.domain.DocumentType

@Suppress("unused")
class TbTradeSynchronizer : TbSynchronizer() {

    override val documentType = DocumentType.TRADE

    override val path = "/tb/trades/page"

    override fun buildDocuments(context: Context, response: Map<String, Any>): List<Document> {
        val data = gson.fromJson(response["data"] as String, JsonArray::class.java)
        return data.map {
            it as JsonObject
            Document(
                it["tid"].asString,
                it["status"].asString,
                it["jdp_response"].asString,
                it["created"].asString.toLocalDateTime(),
                it["jdp_modified"].asString.toLocalDateTime(),
            )
        }
    }
}